/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
// 具体实现文章的**核心业务逻辑**（

package com.yami.shop.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.app.dto.BookDto;
import com.yami.shop.bean.model.Book;
import com.yami.shop.dao.BookMapper;
import com.yami.shop.service.BookService;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公告管理
 *
 * @author hzm
 * @date 2019-04-18 21:21:40
 */
@Service
@AllArgsConstructor
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {

    private BookMapper bookMapper;

    @Override
    @Cacheable(cacheNames = "books", key = "'books'")
    public List<Book> listBook() {
        return bookMapper.selectList(new LambdaQueryWrapper<Book>()
                .eq(Book::getStatus, 1)
                .eq(Book::getIsTop, 1)
                .orderByDesc(Book::getUpdateTime));

    }

    @Override
    @CacheEvict(cacheNames = "books", key = "'books'")
    public void removeBookList() {
    }

    @Override
    public Page<BookDto> pageBook(Page<BookDto> page) {
        return bookMapper.pageBook(page);
    }

    @Override
    @Cacheable(cacheNames = "book", key = "#bookId")
    public Book getBookById(Long bookId) {
        return bookMapper.selectById(bookId);
    }

    @Override
    @CacheEvict(cacheNames = "book", key = "#bookId")
    public void removeBookById(Long bookId) {
    }


}
